﻿@using Microsoft.AspNetCore.Mvc.Localization
@using Skoruba.IdentityServer4.Admin.BusinessLogic.Shared.Dtos.Common
@model Skoruba.IdentityServer4.Admin.BusinessLogic.Dtos.Configuration.ApiSecretsDto
@inject IViewLocalizer Localizer

@{
	ViewBag.Title = Localizer["PageTitle"];
	Layout = "_Layout";
}

<form asp-controller="Configuration" asp-action="ApiSecrets" Method="post">
	<div class="row">

		<div class="col-12">
			<nav aria-label="breadcrumb">
				<ol class="breadcrumb">
					<li class="breadcrumb-item"><a asp-controller="Configuration" asp-action="ApiResources">@Localizer["NavigationApiResources"]</a></li>
					<li class="breadcrumb-item"><a asp-controller="Configuration" asp-action="ApiResource" asp-route-id="@Model.ApiResourceId">@Model.ApiResourceName</a></li>
					<li class="breadcrumb-item active" aria-current="page">@Localizer["NavigationApiSecrets"]</li>
				</ol>
			</nav>
		</div>

		<div class="col-md-12">
			<h3>@Localizer["PageTitle"]</h3>
		</div>

		<div class="col-md-12">
			<div asp-validation-summary="All" class="text-danger"></div>
		</div>

		<div class="col-md-12">
			<div class="card mt-3">
				<h5 class="card-header">@Localizer["PanelNewTitle"]</h5>
				<div class="card-body">

					<!--Hidden -->
					<input type="hidden" asp-for="ApiResourceId" />

					<!--Select-->
					<div class="form-group row">
						<label asp-for="Type" class="col-sm-3 col-form-label">
							@await Html.PartialAsync("Client/Section/Label", "SecretType")
						</label>
						<div class="col-sm-9">
							<select asp-for="Type" asp-items="@(new SelectList(Model.TypeList, "Id", "Text"))" class="form-control single-select"></select>
						</div>
					</div>

					<!--Input - text -->
					<div class="form-group row">
						<label asp-for="Value" class="col-sm-3 col-form-label">
							@await Html.PartialAsync("Client/Section/Label", "SecretValue")
						</label>
						<div class="col-sm-9">
							<input type="text" autocomplete="off" required class="form-control" asp-for="Value">
							<span asp-validation-for="Value" class="text-danger"></span>
						</div>
					</div>

					<!--Select-->
					<div class="form-group row">
						<label asp-for="HashType" class="col-sm-3 col-form-label">
							@await Html.PartialAsync("Client/Section/Label", "HashType")
						</label>
						<div class="col-sm-9">
							<select asp-for="HashType" asp-items="@(new SelectList(Model.HashTypes, "Id", "Text"))" class="form-control single-select"></select>

							<div class="alert alert-warning" role="alert">
								<span class="sr-only">@Localizer["InfoTitle"]</span>
								@Localizer["InfoDescription"]
							</div>
						</div>
					</div>

					<!--Button-->
					<div class="form-group row">
						<label class="col-sm-3 col-form-label">
						</label>
						<div class="col-sm-9">
							<button type="submit" class="btn btn-primary">@Localizer["ButtonAddNewClient"]</button>
						</div>
					</div>
				</div>
			</div>

		</div>
	</div>
</form>

<div class="row">
	<div class="col-md-12">
		<div class="card mt-3">
			<h5 class="card-header">@Localizer["PanelTitle"]</h5>
			<div class="card-body">

				<div class="row table-responsive">
					<table class="table table-striped">
						<thead>
							<tr>
								<th></th>
								<th>@Localizer["TableType"]</th>
								<th>@Localizer["TableValue"]</th>
							</tr>
						</thead>

						<tbody>
							@foreach (var secret in Model.ApiSecrets)
							{
								<tr>
									<td><a asp-action="ApiSecretDelete" asp-route-id="@secret.Id" class="btn btn-danger">@Localizer["TableButtonRemove"]</a></td>
									<td>@secret.Type</td>
									<td>@secret.Value</td>
								</tr>
							}
						</tbody>
					</table>
				</div>

				<div class="row">
					<div class="col-12">
						@await Html.PartialAsync("Common/Pager", new Pager { Action = "ApiSecrets", PageSize = Model.PageSize, TotalCount = Model.TotalCount })
					</div>
				</div>
			</div>
		</div>
	</div>
</div>